<?php
require_once("/../userHelper.php");
require_once("/../databaseHelper.php");
require_once("/../resetDatabase.php");

class userHelperTest extends PHPUnit_Framework_TestCase
{
	public function testGetAllUsernames()
	{
		$allNamesDatabase = userHelper::getAllUsernames();
		
		$allNamesText = array("Han Solo", "Luke Skywalker", "Gandalf", "Aragorn", "Frodo", "Mal Reynolds", "Phu", "River", "Daniel", "Anthony", "Brittany", "Brionna", "Chris", "Mike", "Elizabeth");
		
		$this->assertEquals($allNamesText, $allNamesDatabase);
	}
	
	public function testGetAllUsersWithType()
	{
		$allNamesDatabase = userHelper::getAllUsersWithType();
		
		$allNamesText = array(
			1 => array(5 => "Frodo", 3 => "Gandalf", 1 => "Han Solo", 2 => "Luke Skywalker", 6 => "Mal Reynolds"), 
    		2 => array(12 => "Anthony", 4 => "Aragorn", 10 => "Daniel", 7 => "Phu", 9 => "River"), 
    		3 => array(14 => "Brionna", 13 => "Brittany", 15 => "Chris", 17 => "Elizabeth", 16 => "Mike")
		);
		
		$this->assertEquals($allNamesText, $allNamesDatabase);
	}
	
	public function testUpdateAllUsersType()
	{
		userHelper::updateAllUsersType(array(1 => 2));
		$allNamesDatabase = userHelper::getAllUsersWithType();
		
		$allNamesText = array(
			1 => array(5 => "Frodo", 3 => "Gandalf", 2 => "Luke Skywalker", 6 => "Mal Reynolds"), 
    		2 => array(12 => "Anthony", 4 => "Aragorn", 10 => "Daniel", 1 => "Han Solo", 7 => "Phu", 9 => "River"), 
    		3 => array(14 => "Brionna", 13 => "Brittany", 15 => "Chris", 17 => "Elizabeth", 16 => "Mike")
		);
		
		$this->assertEquals($allNamesText, $allNamesDatabase);
		
		userHelper::updateAllUsersType(array(1 => 1));
	}
	
	public function testGetUserID()
	{
		if(isset($_COOKIE["BuffBoardCookie"]))
		{
			$ret = userHelper::getUserID();
			$this->assertEquals($ret, mysql_real_escape_string($_COOKIE["BuffBoardCookie"]));
		}
		else
		{
			$ret = userHelper::getUserID();
			$this->assertEquals($ret, null);
		}
		
	}
}